package com.hu.juc.day02.T6;

import java.util.concurrent.ArrayBlockingQueue;
import java.util.concurrent.BlockingQueue;
import java.util.concurrent.TimeUnit;

/**
 * 1    两个数据结构：栈/队列
 *       1.1 栈    后进先出
 *       1.2 队列  先进先出
 *       1.3 总结
 * 2    阻塞队列
 *       2.1 阻塞   必须要阻塞/不得不阻塞
 *
 * 3     how
 *
 *  BlockingQueue核心方法
 *  方法类型        抛出异常       特殊值       阻塞          超时
 *   插入           add(e)       offer(e)     put(e)      offer(e,time,unit)
 *   移除          remove()      poll()       take()      poll(time,unit)
 *   检查          element()     peek()       不可用       不可用
 */
public class BlockingQueueDemo {
    public static void main(String[] args) throws InterruptedException {
        BlockingQueue blockingQueue = new ArrayBlockingQueue</*String*/>(3);

        /*System.out.println(blockingQueue.add("a"));
        System.out.println(blockingQueue.add("b"));
        System.out.println(blockingQueue.add("c"));

        System.out.println("--------------");

        System.out.println(blockingQueue.remove());
        System.out.println(blockingQueue.add("x"));*/

        /*System.out.println(blockingQueue.add("c"));
        System.out.println(blockingQueue.element());*/

        /*System.out.println("--------------");

        System.out.println(blockingQueue.offer("a"));
        System.out.println(blockingQueue.offer("b"));
        System.out.println(blockingQueue.offer("c"));*/

       /* System.out.println("--------------");

        System.out.println(blockingQueue.poll());
        System.out.println(blockingQueue.poll());
        System.out.println(blockingQueue.poll());*/

        //一直阻塞
        //blockingQueue.put("a");
        //blockingQueue.put("b");
        //blockingQueue.put("c");
        //blockingQueue.put("d");

        /*System.out.println(blockingQueue.take());
        System.out.println(blockingQueue.take());
        System.out.println(blockingQueue.take());
        System.out.println(blockingQueue.take());*/

        /*System.out.println(blockingQueue.offer("a"));
        System.out.println(blockingQueue.peek());*/

        System.out.println(blockingQueue.offer("a"));
        System.out.println(blockingQueue.offer("b"));
        System.out.println(blockingQueue.offer("c"));

        System.out.println(blockingQueue.offer("a",3L, TimeUnit.SECONDS));
    }
}
